//
// Created by hentai on 24-12-9.
//
#include <stdio.h>
#include <stdlib.h>

#include "cl/hentai_io.h"

#define MAX 41

void readFile() {
    FILE *fp =
        fopen("/home/hentai/CLionProjects/c-cpp-l/resource/text.txt", "r");

    int ch;
    while ((ch = fgetc(fp)) != EOF) {
        putchar(ch);
    }

    fclose(fp);

}

void readFileFpfFsf() {
    FILE *fp;
    char words[MAX];

    if ((fp = fopen("/home/hentai/CLionProjects/c-cpp-l/resource/textf.txt", "a+")) == NULL) {
        fprintf(stdout, "Error opening file\n");
        exit(EXIT_FAILURE);
    }

    puts("input words:");
    while (fscanf(stdin, "%40s", words) == 1 && words[0] != '#') {
        fprintf(fp, "%s", words);
    }

    rewind(fp);
    while (fscanf(fp, "%s", words) == 1) {
        puts(words);
    }

    puts("Down");

    fclose(fp);
}


void readFileFsPs() {
    FILE *fp;
    char words[MAX];
    if ((fp  = fopen("/home/hentai/CLionProjects/c-cpp-l/resource/textf.txt", "a+")) == NULL) {
        puts("Error opening file");
        exit(EXIT_FAILURE);
    }

    puts("input words:");
    while (fgets(words, MAX, stdin) != NULL && words[0] != '#') {
        fputs(words, fp);
    }

    rewind(fp);

    while (fgets(words, MAX, fp) != NULL) {
        fputs(words, stdout);
    }

    fclose(fp);
}

